Fix redundant file rename on Windows; just use cross-platform QFile calls.
authorViet-Tam Luu <viettaml@google.com>
Mon, 4 Dec 2017 22:21:41 +0000 (14:21 -0800)
committerViet-Tam Luu <viettaml@google.com>
Mon, 4 Dec 2017 22:21:41 +0000 (14:21 -0800)
kml.cc

diff --git a/kml.cc b/kml.cc
index f8ff4935b1a2ae582cd4c9b55b1ed75402230b6b..4b75a8b6f3a266ff7a5ecd03196064e3ba2a72f4 100644 (file)
--- a/kml.cc
+++ b/kml.cc
@@ -540,11 +540,10 @@ kml_wr_deinit()
   oqfile = NULL;
 
   if (!posnfilenametmp.isEmpty()) {
-#if __WIN32__
-    MoveFileExW((const wchar_t*) posnfilenametmp.utf16(),
-                (const wchar_t*) posnfilename.utf16(),
-                MOVEFILE_REPLACE_EXISTING);
-#endif
+    // QFile::rename() can't replace an existing file, so do a QFile::remove()
+    // first (which can fail silently if posnfilename doesn't exist). A race
+    // condition can theoretically still cause rename to fail... oh well.
+    QFile::remove(posnfilename);
     QFile::rename(posnfilenametmp, posnfilename);
   }
 }